package protocol.message;

import java.util.Random;
import protocol.ProtocolCode;
import protocol.ProtocolMessage;
import stream.ByteCoding;

/**
 *
 * @author Simão Paulo Rato Alves Reis
 */
public class AccountRegister extends ProtocolMessage {

    private String username, userpass;

    public AccountRegister(String username, String userpass) {
        super();
        connectionid = new Random().nextLong();
        userid = new Random().nextLong();
        this.username = username;
        this.userpass = userpass;
    }

    public AccountRegister(byte[] stream) {
        super(stream);
        username = ByteCoding.setAsString(32, stream);
        userpass = ByteCoding.setAsString(
                40 + ByteCoding.setAsInt(32, stream),
                stream);
    }

    @Override
    public String toString() {
        return "Account Register\n"
                + "Protocol Code: " + ProtocolCode.ACCOUNT_REGISTER
                + super.toString()
                + "\nUser Name: " + username
                + "\nUser Password: " + userpass;
    }

    @Override
    public byte[] getBytes() {
        return ByteCoding.concat(
                ProtocolCode.ACCOUNT_REGISTER.getBytes(),
                ByteCoding.padding(7),
                super.getBytes(),
                ByteCoding.get(username),
                ByteCoding.get(userpass));
    }
}
